package gui.advertiser;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import application.ArenaManager;

public class AddAmountDialog extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField txtfAmount;

	/**
	 * Launch the application.
	 */
	/* public static void main(String[] args) { try { AddAmountDialog dialog =
	 * new AddAmountDialog();
	 * dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	 * dialog.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } */

	/**
	 * Create the dialog.
	 */
	public AddAmountDialog() {
		setVisible(true);
		setBounds(100, 100, 274, 197);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			txtfAmount = new JTextField();
			txtfAmount.setBounds(10, 36, 189, 20);
			contentPanel.add(txtfAmount);
			txtfAmount.setColumns(10);
		}
		{
			JLabel lblAddAmount = new JLabel("Add Amount:");
			lblAddAmount.setBounds(10, 11, 108, 14);
			contentPanel.add(lblAddAmount);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						try {
							int amount = Integer.parseInt(txtfAmount.getText());
							addAmount(amount);
							setVisible(false);
						} catch (NumberFormatException ex) {
							System.out.println("ERROR!");
						}
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						setVisible(false);
						dispose();
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}

	private void addAmount(int amount) {
		ArenaManager.getInstance().addAmount(amount);
	}

}
